import random

def command_close(game, ui):
    cells = [cell for cell in game.hero.env.neighbors
             if cell.feature.is_door and cell.feature.is_open]
    if not cells:
        game.write('There is nothing to close here.')
        return
    cell = random.choice(cells)
    if cell.monster or cell.top_item:
        game.write(game.hero, 'cannot close', cell.feature)
        return
    game.write(game.hero, 'closes', cell.feature)
    cell.feature.state = 'closed'
    game.hero_moved = True
